package com.liehu.business.controller;


import com.liehu.business.pojo.Residence;
import com.liehu.business.pojo.Social;
import com.liehu.business.service.ResidenceService;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Residence的Controller层
 */
@RestController //注明是Controller
@RequestMapping("/residence")
@CrossOrigin //跨域解决
@Api(value = "/residence",description = "入户")
public class ResidenceController {
    @Autowired
    private ResidenceService residenceService;

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有", notes = "查询所有")//描述
    @GetMapping
    public Result findAll(){
        return  new Result(true, StatusCode.OK,"查询成功！",residenceService.findAll());
    }


    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询", notes = "根据id查询")//描述
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id){
        return  new Result(true, StatusCode.OK,"查询成功！",residenceService.findById(id));
    }

    /**
     * 插入
     */
    @ApiOperation(value = "新增一条记录", notes = "新增一条记录-此接口仅适用于客户调用")//描述
    @PostMapping()
    public Result save(@RequestBody Residence residence){
        residenceService.save(residence);
        return  new Result(true, StatusCode.OK,"插入成功！");
    }

    /**
     * 更新
     */
    @ApiOperation(value = "根据Id更新", notes = "根据Id更新-仅限管理员或业务员操作")//描述
    @PutMapping("/{id}")
    public Result update(@RequestBody Residence residence,@PathVariable("id") String id){


        residence.setId(id);
        residenceService.update(residence);
        return  new Result(true, StatusCode.OK,"更新成功！");
    }


    /**
     * 删除
     */
    @ApiOperation(value = "根据Id删除", notes = "根据Id删除，请谨慎使用--仅限管理员操作")//描述
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){
        residenceService.delete(id);
        return  new Result(true, StatusCode.OK,"删除成功！");
    }

}
